


import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

	class Saler{
    public static void main(String args[]) {
        new TestSaler();
    }
}

class TestSaler extends JFrame{
    JLabel lab1,lab2,lab3;
    JTextField text1,text2,text3,text4;
    JButton button;
    JButton button1;
    public TestSaler(){
        init();
        this.setTitle("闭启炼制作简单计算器");
        this.setLocationRelativeTo(null);
        this.setLayout(new FlowLayout());
        this.setSize(400, 120);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }


    void init(){
        lab1=new JLabel("数字1:");
        lab2=new JLabel("数字2:");

        text1=new JTextField(10);
        text2=new JTextField(10);
        text3=new JTextField(15);
        text4=new JTextField(1);


        text3.setEditable(false);
        button=new JButton("加");
        button1=new JButton("除");
        List list=new List();
        list.setSaler(this);

        List1 list1=new List1();
        list1.setSaler(this);

        button.addActionListener(list);
        button1.addActionListener(list1);

        add(lab1);

        add(text1);


        add(text4);
        add(lab2);



        add(text2);


        add(text3);
        add(button);
        add(button1);

    }
}
//********************
class List implements ActionListener{
    TestSaler saler;

    public void setSaler(TestSaler saler) {
        this.saler = saler;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        try {
            double	num=Double.parseDouble(saler.text1.getText());
            double	price=Double.parseDouble(saler.text2.getText());
            saler.text3.setText(num+price+"");
            saler.text4.setText("+");
            Font font=new Font("Times New Roman",Font.BOLD,20);

        }catch(NumberFormatException ex) {
            saler.text3.setText("请输入数字字符");
        }
    }

}


class List1 implements ActionListener{
    TestSaler saler;

    public void setSaler(TestSaler saler) {
        this.saler = saler;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        try {
            double	num=Double.parseDouble(saler.text1.getText());
            double	price=Double.parseDouble(saler.text2.getText());
            saler.text3.setText(num/price+"");
            saler.text4.setText("/");


        }catch(NumberFormatException ex) {
            saler.text3.setText("请输入数字字符");
        }
    }

}


public class Test {


}







